//
//  WHFreedomFishVC.m
//  WHEasyBizLink
//
//  Created by ShengMeng on 9/25/25.
//

#import "WHFreedomFishVC.h"
#import "WHFreedomFishCell.h"
#import "WHEnterpriseCompanyModel.h"
#import "WHHeaderButtonView.h"
#import "WHFreedomFishModel.h"
#import "WHHeaderButtonModel.h"
#import "FishRulesViewController.h"
#import "WHFishSpotModel.h"
#import "SearchTitleView.h"
#import "SDAutoLayout.h"
#import "WHTdsModel.h"
#import "MJRefresh.h"

#define pagesize 80

static NSString *const kCellID = @"WHFreedomFishVCCellID";

@interface WHFreedomFishVC ()<WHHeaderButtonViewDelegate,WHFreedomFishCellDelegate>

@property (nonatomic,assign)int  mPageIndex;
@property(nonatomic,strong)NSString*searchString;
@property(nonatomic,strong)WHHeaderButtonView *headerView;
@property (nonatomic,assign)CGFloat viewHeight;

@property (nonatomic,strong)NSMutableArray*models;

@end

@implementation WHFreedomFishVC


-(instancetype)initWithHeight:(CGFloat)viewHeight
{
    self = [super init];
    if (self)
    {   self.viewHeight = viewHeight;
    }
    return self;
}

- (void)viewDidLoad {
    self.mPageIndex = 1;
    self.searchString = @"";
    [super viewDidLoad];
}

#pragma mark - loadDatas
- (void)loadDatas{
    [super loadDatas];
 
   NSArray *titels =@[@"一号鲤鱼塘",@"二号草鱼塘",@"三号混养鱼塘"];
//    self.headerView.models = [WHFreedomFishModel getMenuDataWithArr:titels];
    self.datas  = [WHFreedomFishModel getDatasModelArr:titels];
//    [self.datas addObject:self.models.firstObject];
//    [self.tableView reloadData];
}

#pragma mark - setupUI
- (void)setupUI{
    [super setupUI];
    //一个简单的super setupUI = createTableView
    
//    self.headerView.frame = CGRectMake(0,0,ScreenW-40,70);
//    self.tableView.tableHeaderView = self.headerView;
    self.tableView.frame =CGRectMake(0,0,ScreenW-40,self.viewHeight);
}

-(void)rightBarButtonItemClicked
{

}
#pragma mark 下拉刷新开始
- (void)dropDownRefresh
{
    if(!self.tableView.mj_footer) return;
    self.mPageIndex++;
}

- (void)setViewFooterWithHave:(BOOL) have{
    if(have){
        self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
            [self dropDownRefresh];
        }];
    }else{
        self.tableView.mj_footer =nil;
    }
}

- (void)setViewFooterEndRefresh{
    [self.tableView.mj_footer endRefreshing];
}

#pragma mark - <tableViewDelegate>
- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath{
   

    WHFreedomFishCell *cell =[tableView dequeueReusableCellWithIdentifier:kCellID];
    if (!cell) {
        cell = [[WHFreedomFishCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellID];
    }
    cell.model = self.datas[indexPath.row];
    cell.delegate = self;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView
 heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 150;
    //return kMarginH*16;
}

-(void)tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
   
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

}

-(void)wHFreedomFishCellBtnClick:(WHFreedomFishModel *)model
{
    FishRulesViewController *vc = [[FishRulesViewController alloc] init];
    vc.title             = model.name;
    [self.navigationController pushViewController:vc animated:YES];

}

//-(void)WHHeaderButtonViewWithModel:(WHHeaderButtonModel *)model
//{
//    
//    [self.datas removeAllObjects];
//    [self.datas addObject:self.models[[model.code intValue]]];
//    [self.tableView reloadData];
//}
-(WHHeaderButtonView *)headerView
{
    if (!_headerView)
    {
        _headerView=[[WHHeaderButtonView alloc]initWithFrame:CGRectMake(0,0,ScreenW-40,50) type:WHButtonBackground];
        _headerView.delegate = self;
        _headerView.backgroundColor = [UIColor clearColor];
    }
    return  _headerView;
}

@end
